package Effects;

import View.Load;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

public class Loading {

    public int listener;

    public int getListener() {
        return listener;
    }

    public void setListener(int listener) {
        this.listener = listener;
    }

    public void contagem() {
        effectLoading();
        new Thread() {
            @Override
            public void run() {
                while (true) {
                    for (int i = 0; i <= 100; i++) {
                        try {
                            sleep(100);
                            if (i == 100) {
                                setListener(1);
                                Adjust.startMainScreen();
                                stop();                                
                            }
                        } catch (InterruptedException ex) {
                            Logger.getLogger(Loading.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                }
            }
        }.start();
    }

    public void effectLoading() {
        new Thread() {
            @Override
            public void run() {

                while (true) {
                    try {
                        for (int i = 1; i <= 4; i++) {
                            sleep(100);
                            Load.effect.setIcon(new ImageIcon(
                                    "C:\\Users\\Jorge\\Documents\\NetBeansProjects\\"
                                    + "Project_Chelp_v1.0.0\\src\\Loading_Effect\\" + i + ".png"));
                        }
                        getListener();
                        if (getListener() == 1) {
                            this.stop();
                        }
                    } catch (InterruptedException ex) {
                        JOptionPane.showMessageDialog(null, "Erro");
                    }
                }
            }
        }.start();
    }
}